<!DOCTYPE html>
<html>

<head>
    <title>预约信息</title>
    <%- include('./_global/appendJs') %>

</head>
<style>
    .doctor-img {
        width: 3.9rem;
        height: 3.9rem;
        float: left
    }
</style>


<body>
    <section class="page-wrap yyxx-box">
        <!-- <header class="header-box grey fixed header">
            <div class="header-content">
                <div class="left-tool">
                    <a class="back" href="javascript:void(0)">
                        <i class="iconfont icon-back"></i>
                    </a>
                </div>
                <div class="title">预约信息</div>
            </div>
        </header> -->
        <div class="first-box">
            <i class="doctor-img"></i>
            <div class="text-box">
                <p>
                    <span class="name-span doctor" name="docName">龚海荣</span>
                    <span class="doctor" name="docTitle">副主任医师</span>
                </p>
                <p>
                    <span class="doctor" name="hosName">万达医院</span>
                    <span class="doctor" name="depName">呼吸科</span>
                </p>
            </div>
        </div>
        <div class="second-list-box">
            <ul>
                <li>
                    <span class="text-left">就诊时间</span>
                    <span class="text-right scheduleDate"></span>
                </li>
                <li>
                    <span class="text-left">门诊类型</span>
                    <span class="text-right regType"></span>
                </li>
                <!--<li>-->
                <!--<span class="text-left">挂号费用</span>-->
                <!--<span class="text-right"><span class="yellow-text visitCost">36元</span></span>-->
                <!--</li>-->
            </ul>
        </div>
        <div class="last-box">
            <a>
                <span class="text-left">就诊人</span>
                <span class="text-right">
                    <span class="blue-text" id="jzr"></span>
                    <!--  <i class="arrow-right"></i> -->
                </span>
            </a>
        </div>


        <div class="qd-btn-box">
            <a class="qd-btn" href="javascript:void(0);">确定预约</a>
        </div>
    </section>
    <script src="/static/lib/forweb.js"></script>
    <script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
    <script src="/static/js/<%=type%>/pageUrl.js"></script>
    <script src="/static/js/<%=type%>/yygh.js"></script>
    <script type="text/javascript">
        var userInfo = StoreCache.getCache("yyghUserInfo");
        var getSourceInfo = StoreCache.getCache("YYGH_HYINFO");
        var getHosInfo = StoreCache.getCache("YYGH_HOSINFO");
        var yyghDocInfo = StoreCache.getCache("YYGH_YSINFO");
        var page_yyInfo = (function ($, page_yyInfo) {
            var uid = StoreCache.getCache("uid");
            /**加载视图*/
            function initView() {
                /**ui脚本*/
                $('.pay-list-box').find("li").click(function () {
                    if (!$(this).hasClass('active')) {
                        $(this).addClass('active').siblings().removeClass('active');
                    } else {
                        $(this).removeClass('active');
                    }
                })
            }

            /**加载数据*/
            function initData() {
                /**加载医生信息*/
                var docInfo = StoreCache.getCache("YYGH_YSINFO");
                var hosInfo = StoreCache.getCache("YYGH_HOSINFO");
                docInfo['hosName'] = hosInfo.hosName;
                if (docInfo["orderType"] == "2") {
                    // $(".first-box").find(".name-span").parent().hide();
                    $(".first-box").find(".doctor[name='docName']").text("");
                    $(".first-box").find(".doctor[name='docTitle']").text("");
                    $(".first-box").find(".doctor[name='hosName']").text(docInfo["hosName"]);
                    $(".first-box").find(".doctor[name='depName']").text(docInfo["depName"]);
                    var docImgUrl = "/static/images/icon_ptmz.png";

                    $(".doctor-img").attr("style", "background:url('" + docImgUrl +
                        "') no-repeat;background-size: 100% 100%;");
                } else {

                    $(".first-box").find(".doctor").each(function () {
                        $(this).text(docInfo[$(this).attr("name")]);
                    });
                    var docImgUrl = docInfo["docImgUrl"];
                    if (!docInfo["docImgUrl"]) {
                        docImgUrl = "/static/images/doctor_image.jpg";
                    }
                    $(".doctor-img").attr("style", "background:url('" + docImgUrl +
                        "') no-repeat;background-size: 100% 100%;");

                }


                /**加载号源信息*/
                var hyInfo = StoreCache.getCache("YYGH_HYINFO") ? StoreCache.getCache("YYGH_HYINFO") : docInfo;
                $(".scheduleDate").text(hyInfo["scheduleDate"]);
                $(".regType").text(page_yyInfo.getRegType(hyInfo["regType"]));
                $(".visitCost").text(page_yyInfo.getVisitCost(hyInfo["visitCost"]));

                // 加载就诊人信息
                queryPatientInformation(uid);



            }


            // 加载就诊人信息
            function queryPatientInformation(uid) {

                $.ajax({
                    type: "GET", // 使用get方法访问后台
                    dataType: "json", // 返回json格式的数据
                    "headers": {
                        "Content-Type": "application/json",
                        "Cache-Control": "no-cache",
                    },
                    url: "/api1/changping-user/api/customer/findCustomerByUid?uid=" + uid, // 要访问的后台地址
                    success: function (data) {
                        if (data.code == "0") {
                            if (data && data.data) {
                                $("#jzr").data("info", data.data);
                                $("#jzr").text(data.data.name);

                            }
                        } else {
                            $.QuickAlert.alertFail({
                                content: data.message
                            });
                        }
                    }
                });
            }


            /**获取门诊类型*/
            function getRegType(regType) {
                var value = "";
                if (regType == "100") {
                    value = "普通门诊";
                } else if (regType == "101") {
                    value = "专科门诊";
                } else if (regType == "102") {
                    value = "专家门诊";
                } else if (regType == "103") {
                    value = "特需门诊";
                } else if (regType == "104") {
                    value = "专病门诊";
                } else if (regType == "999") {
                    value = "其它门诊";
                }
                return value;
            }

            function getVisitCost(visitCost) {
                var value = "0";
                if (!StringUtils.isEmpty(visitCost)) {
                    value = visitCost;
                }
                return value + "元";
            }
            var cfg_def = {
                initView: initView,
                initData: initData,
                getRegType: getRegType,
                getVisitCost: getVisitCost,
            }

            page_yyInfo.init = function (cfg) {
                $.extend(page_yyInfo, cfg_def, cfg);
                page_yyInfo.initData();
                page_yyInfo.initView();
                // yyghSetControl();
                $(".qd-btn").on("click", function () {
                    var jzrInfo = $("#jzr").data("info");
                    /**号源预约*/
                    var hyInfo = StoreCache.getCache("YYGH_HYINFO");
                    var hosInfo = StoreCache.getCache("YYGH_HOSINFO");
                    var params = {};
                    params["hosCode"] = hyInfo["hosCode"];
                    params["depCode"] = hyInfo["depCode"];
                    params["hosName"] = hosInfo ? hosInfo["hosName"] : hyInfo["hosName"];
                    params["docCode"] = hyInfo["docCode"];
                    params["doctName"] = hyInfo["docName"];
                    params["oneDepCode"] = hyInfo["oneDepCode"];
                    // params["regType"] = hyInfo["regType"];
                    params["numSourceCode"] = hyInfo["numSourceCode"];
                    params["scheduleCode"] = hyInfo["scheduleCode"];
                    params["payMode"] = "3";
                    // params["mediCardId"] = mrJzkInfo["jzkh"];
                    // params["mediCardType"] = mrJzkInfo["jzklx"];


                    /*
                    params["visitCost"] = hyInfo["visitCost"];
                    params["payState"]="2",
                    params["password"] = "123456";*/

                    params["patientCardType"] = jzrInfo["cardType"];
                    params["patientCardId"] = jzrInfo["personcard"];
                    params["patientPhone"] = jzrInfo["mobilePhone"];
                    params["patientName"] = jzrInfo["name"];
                    params["patientGender"] = jzrInfo["gender"];
                    params["replaceUserCardType"] = "1";
                    params["replaceUserCardId"] = jzrInfo["personcard"];
                    params["replaceUserName"] = jzrInfo["name"];
                    params["ipAddr"] = "1";
                    params["macAddr"] = "1";
                    params["patient_type"] = "1";
                    params["orderType"] = hyInfo["orderType"];
                    // date = new Date(jzrInfo["csrq"].replace(/(\d{4})(\d{2})(\d{2})/g, '$1-$2-$3'));
                    params["birthday"] = jzrInfo["birthday"];
                    if (yyghDocInfo["orderType"] == "2") {
                        params["resourceCode"] = yyghDocInfo["resourceCode"];
                    } else {

                        params["resourceCode"] = hyInfo["docCode"];
                    }
                    //  params["orderType"]="1";
                    params["orderTime"] = hyInfo["scheduleDate"];
                    params["timeRange"] = hyInfo["timeRange"];
                    params["visitLevel"] = hyInfo["regType"];
                    params["deptName"] = hyInfo["depName"];
                    params["regType"] = hyInfo["regType"];
                    saveYyghInfo(params);

                });

            }



            function saveYyghInfo(params) {
                $.ajax({
                    type: "POST", // 使用get方法访问后台
                    dataType: "json", // 返回json格式的数据
                    "headers": {
                        "Content-Type": "application/json",
                        "Cache-Control": "no-cache",
                    },
                    url: "/api/yyghAdapter/submitOrderByUserInfo", // 要访问的后台地址
                    data: JSON.stringify(params),
                    success: function (data) {
                        if (data.code == "SUCCESS") {
                            if (data && data.data) {
                                $.QuickAlert.alertNormal("预约成功！", {
                                    callback: function () {
                                        var isReg = getSourceInfo["regType"] == "102" ?
                                            (page_yyInfo.getRegType(getSourceInfo[
                                                    "regType"]) + " (" + getSourceInfo.docName +
                                                "医生)") : (page_yyInfo.getRegType(
                                                    getSourceInfo["regType"]));

                                        var sendMsg = {
                                            phone: userInfo.mobilePhone,
                                            // phone: "18501614744",
                                            content: "【" + getSourceInfo.hosName +
                                                "】" + userInfo.name + ",您已成功预约" +
                                                getSourceInfo.scheduleDate +
                                                "，科室名称 " + getSourceInfo.depName + " " + isReg + "，医事服务费" +
                                                getSourceInfo.visitCost + "元，治疗时间为" +
                                                getSourceInfo.startTime + "-" +
                                                getSourceInfo.endTime +
                                                "。请您携带身份证、医保卡提前半小时到预约窗口取号等待就诊。如遇特殊情况医生停诊，我们将短信通知您，给您带来的不便敬请谅解。祝您生活愉快！医院咨询电话：" +
                                                getHosInfo.lxdh

                                        };

                                        // 发送短信
                                        $.ajax({
                                            type: "POST", // 使用get方法访问后台
                                            dataType: "json", // 返回json格式的数据
                                            "headers": {
                                                "Content-Type": "application/json",
                                                "Cache-Control": "no-cache",
                                            },
                                            url: "/api/yyghAdapter/sendMsg", // 要访问的后台地址
                                            data: JSON.stringify(sendMsg),
                                            success: function (result) {
                                                if (result.code == "SUCCESS") {
                                                    $.pageSwitch.goToUrl(
                                                        "myOrder",
                                                        "yyDetail",
                                                        "orderId=" +
                                                        data.data.yydbh +
                                                        "&hosCode=" +
                                                        data.data.hosOrgCode
                                                    );
                                                } else {
                                                    $.QuickAlert.alertFail({
                                                        content: result
                                                            .message
                                                    });
                                                }
                                            }
                                        });






                                    }
                                });



                            }
                        } else {
                            $.QuickAlert.alertFail({
                                content: data.message
                            });
                        }
                    }
                });
            }

            return page_yyInfo;
        })(jQuery, {});
    </script>
</body>

</html>